<template>
  <div class="app-container">
    <el-form :inline="true" label-width="80px">
      <el-form-item label="手机号码">
        <el-input
          v-model="queryParams.mobile"
          placeholder="手机号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="昵称/姓名" >
        <el-input
          v-model="queryParams.nickname"
          placeholder="昵称/姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="订单编号" >
        <el-input
          v-model="queryParams.payno"
          placeholder="订单编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item label="奖励时间">
        <el-date-picker
          v-model="startTime"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-table  v-loading="loading" :data="postList" >
      <el-table-column label="订单编号" align="center" prop="payno">
        <template slot-scope="scope">
          <el-popover placement="top-start" title="订单编号" width="250" trigger="hover">
            <div>{{scope.row.payno}}</div>
            <span slot="reference" v-if="scope.row.payno" >{{ scope.row.payno.substr(0,10)+'...' }}</span>
            <span slot="reference" v-else class="text-info">无</span>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="头像" align="center" prop="path">
        <template   slot-scope="scope">
          <div>
            <el-popover placement="right" title="" trigger="click">
              <img :src="scope.row.path"  alt="">
              <img slot="reference" :src="scope.row.path" alt="" style="max-height: 50px;max-width: 50px">
            </el-popover>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="用户昵称" align="center" prop="nickname" :show-tooltip-when-overflow="true" />
      <el-table-column label="真实姓名" align="center">
        <template slot-scope="scope">
          <span :class="scope.row.realname?'':'text-warning'">{{ scope.row.realname?scope.row.realname:'未实名' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="手机号" align="center" prop="mobile"/>
      <el-table-column label="角色" align="center" prop="role"  :formatter="roleFormat" />
      <el-table-column label="购买用户" align="center" prop="buyNickname" :show-tooltip-when-overflow="true">
        <template slot-scope="scope">
          <span  v-if="scope.row.buyIdNo&&scope.row.buyNickname">{{ scope.row.buyIdNo+'/'+scope.row.buyNickname}}</span>
          <span v-else class="text-warning">无</span>
        </template>
      </el-table-column>
      <el-table-column label="购买数量" align="center" prop="number" />
      <el-table-column label="购买时间" align="center" prop="buyCreatetime" :show-tooltip-when-overflow="true"/>

      <el-table-column label="支付金额" align="center" prop="totalamount" >
        <template slot-scope="scope">
          <span>{{formatCurrency(scope.row.totalamount) }}</span>
        </template>
      </el-table-column>

      <el-table-column label="推荐奖励" align="center" >
        <template slot-scope="scope">
          <span>{{formatCurrency(scope.row.upincome) }}</span>
        </template>
      </el-table-column>

      <el-table-column label="奖励时间" align="center" prop="createtime" :show-tooltip-when-overflow="true"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
  import {listUserAsset} from "@/api/maker/reward";
  export default {
    data() {
      return {
        startTime:'',
        // 遮罩层
        loading: false,
        // 总条数
        total: 0,
        // 岗位表格数据
        postList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 状态数据字典
        statusOptions: [],
        roleOptions:[],
        sourceOptions:[],
        options:[],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          mobile: undefined,
          nickname: undefined,
          startTime:undefined,
          endTime:undefined,
          payno:undefined,
        },
        form: {

        },
        rules:{}
      };
    },
    created() {
      this.getDicts("yy_user_role").then(response => {
        this.roleOptions = response.data;
      });
      this.getDicts("yy_maker_source").then(response => {
        this.sourceOptions = response.data;
      });
      this.getList();
    },
    methods: {
      getList() {
        this.loading = true;
        listUserAsset(this.queryParams).then(response => {
          this.postList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      handleQuery() {
        if(this.startTime){
          this.queryParams.startTime= this.startTime[0]+" 00:00:00";
          this.queryParams.endTime=this.startTime[1]+" 23:59:59";
        }else{
          this.queryParams.startTime=null;
          this.queryParams.endTime=null;
        }
        this.queryParams.pageNum = 1;
        this.getList();
      },
      sourceFormat(row,column){
        return this.selectDictLabel(this.sourceOptions, row.source);
      },
      roleFormat(row,column){
        return this.selectDictLabel(this.roleOptions, row.role);
      }
    }
  }
</script>

<style scoped>

</style>
